async function log({ bgColor, color, msg }) {
  if (!bgColor) {
    bgColor = 'rgba(52,117,173,1)';
  }

  if (!color) {
    color = '#fff';
  }

  const lableStyle =
    'background:rgba(96,96,96,1);font-size:12px;padding:2px 10px;color:#fff;border-top-left-radius:4px;border-bottom-left-radius:4px;';
  const msgStyle = `background:${bgColor};font-size:12px;padding:2px 10px;color:${color};border-top-right-radius:4px;border-bottom-right-radius:4px;`;

  console.info(msg, lableStyle, msgStyle);
}

function plusReady(callback) {
  callback();
  if (window.plus) {
    setTimeout(() => {
      callback();
    }, 0);
  } else {
    document.addEventListener(
      'plusready',
      () => {
        callback();
      },
      false,
    );
  }
}

function checkToken(message = '登录过期，请重新登录') {
  return this.$dialog
    .confirm({
      title: '提示',
      message,
    })
    .then(() => {
      this.$store.commit('common/initData');
      this.$store.commit('common/setChat', []);
      this.router.replace({
        path: '/login',
      });
    });
}

export default {
  log,
  checkToken,
  plusReady,
};
